package com.ruoyi.project.other.cost.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.other.cost.domain.Cost;
import com.ruoyi.project.other.cost.domain.CostData;
import com.ruoyi.project.other.cost.service.CostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理费控制
 */
@Controller
@RequestMapping("/other/cost")
public class CostController extends BaseController {

    private String prefix = "other/cost";

    @Autowired
    private CostService costService;

    @RequiresPermissions("other:cost:view")
    @GetMapping("")
    public String cost(){
        return prefix+"/cost";
    }

    /**
     * 多条件查询管理费
     * @param cost
     * @return
     */
    @RequiresPermissions("other:cost:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findCost(Cost cost){
        startPage();
        List<Cost> list = costService.findCost(cost);
        return getDataTable(list);
    }

    @RequiresPermissions("other:cost:list")
    @PostMapping("/findDate")
    @ResponseBody
    public CostData findDate(){
        CostData costData = costService.findData();
        return costData;
    }

    @RequiresPermissions("other:cost:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cost cost) {
        List<Cost> list = costService.findCost(cost);
        ExcelUtil<Cost> util = new ExcelUtil<Cost>(Cost.class);
        return util.exportExcel(list, "管理费数据");
    }

    /**
     * 删除管理费
     */
    @RequiresPermissions("other:cost:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(costService.deleteTCostByIds(ids));
    }

    /**
     * 修改管理费
     */
    @RequiresPermissions("other:cost:edit")
    @GetMapping("/edit/{costHostid}")
    public String edit(@PathVariable("costHostid") Integer costHostid, ModelMap mmap)
    {
        Cost cost = costService.findCostById(costHostid);
        mmap.put("cost", cost);
        return prefix + "/edit";
    }

    /**
     * 保存修改管理费
     */
    @RequiresPermissions("other:cost:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Cost cost)
    {
        return toAjax(costService.changeCost(cost));
    }

    /**
     * 显示免缴月份
     */
    @RequiresPermissions("other:cost:view")
    @GetMapping("/showMjmonth")
    public String showMjmonth()
    {
        return prefix + "/mjMonth";
    }

    /**
     * 查询免缴月份
     * @return
     */
    @RequiresPermissions("other:cost:edit")
    @PostMapping("/findMjMonth")
    @ResponseBody
    public String findMjMonth(){
        String mjMonth = costService.findMjMonth();
//      System.out.println(mjMonth);
        return mjMonth;
    }
}
